﻿using UnityEngine;
using System.Collections.Generic;
using CommonFactory;

namespace CharacterSystem
{
    public class CharacterManager : ICharacterManager
    {
        HeroInfo HeroInfo;

        List<ICharacterSpawn> characterSpawns = new List<ICharacterSpawn>();

        public void Init()
        {
            HeroInfo = Resources.Load<HeroInfo>("ScriptableObject/HeroInfo");
        }

        public ICommonProductData GetCharacterDataByID(int id)
        {
            for (int i = 0; i < HeroInfo.Data.Count; i++)
            {
               if(HeroInfo.Data[i].ID == id)
                {
                    return HeroInfo.Data[i];
                }
            }
            return null;
        }

        public void RegisterSpawn(ICharacterSpawn spawn)
        {
            if (!characterSpawns.Contains(spawn))
            {
                characterSpawns.Add(spawn);
            }
        }

        public void RemoveSpawn(ICharacterSpawn spawn)
        {
            if (characterSpawns.Contains(spawn))
            {
                characterSpawns.Remove(spawn);
            }
        }
    }
}